import axios from "axios";
import { ElLoading } from "element-plus";

let loadingInstance = null;
let baseURL = ''
console.log("环境变量-----、变量", process.env);
// 创建axios实例对象 调用拦截方法

if(process.env.NODE_ENV==="production"){
    console.log("生产环境");
    baseURL = process.env.VUE_APP_TT_URL;
}else{
    console.log("其他环境");
    baseURL='/douyu'
}

const instance = axios.create({
    baseURL,
});
// 请求拦截
instance.interceptors.request.use(
    function (config) {
        loadingInstance = ElLoading.service({
            text:'加载中',
            lock:true,
            background:"rgba(0,0,0,.3)",
        });
        console.log("在发送请求之前做些什么---config", config);
        return config;  
    },
    function(error){
        return Promise.reject(error);
    }
);
// 响应拦截

instance.interceptors.response.use(
    function(response){
        loadingInstance.close();
        return response.data;
    },
    function(error){
        loadingInstance.close();
        return Promise.reject(error);
    }
);
export default instance;

